class Solution:
    def findErrorNums(self, nums: list[int]) -> list[int]:
        flag = set()
        res = []
        for num in nums:
            if num in flag:
                res.append(num)
            flag.add(num)
        for i in range(1, len(nums) + 1):
            if i not in flag:
                res.append(i)
                break
        return res
